package com.gss.entity.generator;

import java.lang.reflect.Field;

public class ClassAnnotationUtil {

    /**
     * 给类上所有的属性添加注解
     * @param clz
     * @param annoStr
     */
    public static void parse(Class clz,String annoStr){
        StringBuffer buffer = new StringBuffer();

        Field[] declaredFields = clz.getDeclaredFields();
        for (Field field : declaredFields) {
            field.setAccessible(true);
            Class<?> type = field.getType();
            String simpleName = type.getSimpleName();

            String fileName = field.getName();
            //注解
            String currAnn = annoStr.replace("{name}",fileName);
            //首字母转换为小写
            char c = fileName.charAt(0);
            String head = (c + "").toLowerCase();
            String newFileName = head + fileName.substring(1);
            //打印
            buffer.append(currAnn + "\n");
            buffer.append("private " + simpleName + " " + newFileName + ";\n");

        }

        System.out.println(buffer.toString());

    }

    public static void main(String[] args) {
    }


}
